#include <stdio.h>
#define MAX_SIZE 100000

int main()
{
    int N, ind, temp[MAX_SIZE], start;
    int count = 0, Temp;
    int s_count = 0;
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
    {
        scanf("%d", &ind);
        temp[ind] = i;
        if (ind == 0)
            start = i;
    }
    while(1)
    {
        while (temp[s_count] != s_count)
        {
            //swap
            Temp = temp[start];
            temp[start] = start;
            temp[s_count] = Temp;
            start = Temp;
            count++;
        }

        while(temp[++s_count] == s_count);
        if(s_count>=N)
            break;

        //swap two num and count for another loop 
        temp[start] = temp[s_count];
        temp[s_count] = 0;
        count++;

    }
    printf("%d", count);
    return 0;
}